package com.ljsw.dialog;

import com.ljsw.activity.R;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

/**
 * 员工信息Dialog
 * 作者: 石锚
 * 版本: 1.0
 * 日期: 2015-10-15
 */
public class YuangongDialog {
	public YuangongDialog(Context context) {
		super();
		this.context = context;
		WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		display = windowManager.getDefaultDisplay();//获取屏幕分辨率
	}
	
	private Context context;
	private Display display;
	private Dialog dialog;
	private LinearLayout yg_layout;
	private TextView danwei_name,//单位名称|机构名称
					 gonghao,//工号
					 yg_name,//姓名
					 shenfenzheng;//身份证
	private ImageView image_yuangong;//图片
	
	public YuangongDialog builder(){
		View view = LayoutInflater.from(context).inflate(R.layout.dialog_yuangong, null);
		yg_layout = (LinearLayout) view.findViewById(R.id.yg_layout);
		danwei_name = (TextView) view.findViewById(R.id.danwei_name);
		gonghao = (TextView) view.findViewById(R.id.gonghao);
		yg_name = (TextView) view.findViewById(R.id.yg_name);
		shenfenzheng = (TextView) view.findViewById(R.id.shenfenzheng);
		image_yuangong = (ImageView) view.findViewById(R.id.image_yuangong);
		// 添加Dialog样式
		dialog = new Dialog(context, R.style.YuangongDialog);
		dialog.setContentView(view);
		dialog.setCanceledOnTouchOutside(true);// 设置点击Dialog外部任意区域不关闭Dialog	
		// 调整dialog背景大小
		yg_layout.setLayoutParams(new FrameLayout.LayoutParams(
				(int) (display.getWidth() * 0.85), LayoutParams.WRAP_CONTENT));
		return this;
	}
	/**
	 * 设置工号
	 * @param title
	 * @return
	 */
	public YuangongDialog setGonghao(String title){
		gonghao.setText(title);
		return this;
	}
	/**
	 * 设置 员工名字
	 * @param title
	 * @return
	 */
	public YuangongDialog setYgname(String title){
		yg_name.setText(title);
		return this;
	}
	
	/**
	 * 设置 身份证
	 * @param title
	 * @return
	 */
	public YuangongDialog setShenfenzheng(String title){
		shenfenzheng.setText(title);
		return this;
	}
	
	/**
	 * 设置单位名
	 * @param title
	 * @return
	 */
	public YuangongDialog setDanweiName(String title){
		danwei_name.setText(title);
		return this;
	}
	
	/**
	 * 设置图片
	 * @param title
	 * @return
	 */
	public YuangongDialog setHeadBitmap(Bitmap map){	
		image_yuangong.setImageBitmap(map);
		return this;
	}
	
	/**
	 * 点击事件
	 * @param text
	 * @param listener
	 * @return
	 */
	public YuangongDialog setQueDing(String text,
			final OnClickListener listener) {
		yg_layout.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				listener.onClick(v);
				dialog.dismiss();
			}
		});
		return this;
	}
	public void show() {
		dialog.show();
	}
	
}
